package com.ruoyi.util.voice;


import com.ruoyi.util.voice.vo.request.MiddleNumberUnbindVo;
import com.ruoyi.yunxin.domain.MiddleRelation;
import com.ruoyi.yunxin.mapper.MiddleRelationMapper;
import com.ruoyi.yunxin.mapper.VoiceTemplateConfigMapper;
import com.winnerlook.model.PrivacyUnbindBody;
import com.winnerlook.model.VoiceResponseResult;
import com.winnerlook.service.VoiceSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author 🤙🤙🏼🤙🏽
 * @date 2025 4月 08 09:39
 * @Description
 */
@Component
@Slf4j
public class VoiceUtil {
    @Resource
    private MiddleRelationMapper middleRelationMapper;
    @Resource
    private VoiceTemplateConfigMapper voiceTemplateConfigMapper;
    private final String successCode = "000000";

    /**
     * 隐私小号AXB解绑
     *
     * @param unBindVo
     * @return
     * @throws Exception
     * @Date 2025 4月 08 11:47
     */
    public Integer middleNumberUnbind(MiddleNumberUnbindVo unBindVo) throws Exception {
        String middleNumber = voiceTemplateConfigMapper.selectOneData("middleNumber");
        String accountId = voiceTemplateConfigMapper.selectOneData("accountId");
        String token = voiceTemplateConfigMapper.selectOneData("token");
        int result = 0;
        PrivacyUnbindBody unbindBody = new PrivacyUnbindBody();
        unbindBody.setBindNumberA(unBindVo.getBindNumberA());
        unbindBody.setBindNumberB(unBindVo.getBindNumberB());
        unbindBody.setMiddleNumber(middleNumber);
        unbindBody.setMode(unBindVo.getMode());
        VoiceResponseResult voiceResponseResult = VoiceSender.httpPrivacyUnbind(unbindBody, accountId, token);
        if (voiceResponseResult.getResult().equals(successCode)) {
            MiddleRelation middleRelation = middleRelationMapper.selectOneByNumA(unBindVo.getBindNumberA());
            result = middleRelationMapper.deleteMidRelation(middleRelation.getId());
        }
        //else {
        //    throw new RuntimeException("解绑失败:"+voiceResponseResult.getMessage());
        //}
        return result;
    }
}
